'use strict';

angular.module('xianwan')
	.factory('Remind', function ($rootScope, SystemSetting, SettingConstant, AuthService) {

		return {

			playVoice: function (message) {
				/* 紧急呼叫提醒信息 */
				if (message.body.emergency) {
					let audio = document.getElementById("msgVoice");
					audio.play();
					return;
				}
				if (SystemSetting.getSystemSettingByType(SettingConstant.SOUND) == false) {
					return;
				}
				if (message.from === AuthService.currentUserId()) {
					return;
				}
				if ($rootScope.messages[message.identifier] && $rootScope.messages[message.identifier].remind == false) {
					return;
				}
				let audio = document.getElementById("msgVoice");
				/**
				 * 音频太长，上一次没有播放完时会导致下一次播放不生效，因此需要手动关闭上一次的播放操作 @20180814
				 */
				if (!audio.ended) {
					audio.load();
				}
				audio.play();
			}

		}

	});